class SideBar {
    Blog _blog;
    GetPostsByDate _postsByDate;
    GetPostsByTag _postsByTags;
    GetPostsByUsers _postsByUsers;
    var _active;
	var _prevActive;
    SideBar(Blog b){
      _blog = b;
      _postsByDate = new GetPostsByDate(_blog);
	  _postsByTags = new GetPostsByTag(_blog,this,b.getURL());
	  _postsByUsers = new GetPostsByUsers(_blog);
  }
  
  void setActive(var active){
	reset();
	_prevActive = _active;
	_active = active;
	_active.attributes['class'] = 'active';
  }
  
  void revert(){
	reset();
	_active = _prevActive;
	_active.attributes['class'] = 'active';
  }
  
  void showSideBar(String curruser){
  	//show side bar in HTML
    document.query('#sidebar').innerHTML = Windows.getSideBar(curruser);
	document.query('#allposts').on.click.add((events) => showAll());
  	document.query('#MakePost').on.click.add((events) => pressPostText());
  	document.query('#filterByDates').on.click.add((events) => pressPostByDates());
	document.query('#filterByTags').on.click.add((events) => pressGetPostsByTag());
	document.query('#filterByUser').on.click.add((events) => pressPostByUsers());
	setActive(document.query('#allposts'));
  }
  
	void hideNewPostBtn(){
		document.query('#newpostbtn').innerHTML = '';
	}
  
	void showNewPostBtn(){
		document.query('#newpostbtn').innerHTML = 'NEW POST';
	}
  
  void showAll(){
	_prevActive = document.query('#allposts');
	// close all windows
	_postsByDate.closeWindow();
	_postsByTags.closeWindow();
	_postsByUsers.closeWindow();
    _blog.setPostRequester(new PostsReq(_blog,_blog.getURL()));
	_blog.showPosts();
	setActive(document.query('#allposts'));
	document.query('#pagename').innerHTML = 'All Posts';
  }
  
  void reset(){
  	if(_blog.isLogginedIn()){
  		document.query('#MakePost').attributes['class'] = '';
  	}
	document.query('#allposts').attributes['class'] = '';
    document.query('#filterByUser').attributes['class'] = '';
    document.query('#filterByDates').attributes['class'] = '';
    document.query('#filterByTags').attributes['class'] = '';
	
  }

  void pressPostText(){
	MakeNewPost postMaker = _blog.getPostMaker();
	postMaker.showWindow();
  }
  
  void pressPostByDates(){
//	reset();
//  document.query('#filterByDates').attributes['class'] = 'active';
    _postsByDate.showWindow();

  }
  
	void pressPostByUsers(){
//		reset();
//		document.query('#filterByUser').attributes['class'] = 'active';
		_postsByUsers.showWindow();
	}
  
  void pressGetPostsByTag(){
//	reset();
//  document.query('#filterByTags').attributes['class'] = 'active';
  _postsByTags.showWindow();
  }
  
}
